/**
 * 客服处理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户申诉处理</el-breadcrumb-item>
    </el-breadcrumb>

    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="id" label="申诉ID" width="200">
      </el-table-column>
      <el-table-column sortable prop="userName" label="用户名称" width="200">
      </el-table-column>
      <el-table-column sortable prop="orderOn" label="订单编号" width="200">
      </el-table-column>
      <el-table-column sortable prop="content" label="申诉内容" width="200">
      </el-table-column>
      <el-table-column sortable prop="serviceState" label="处理状态" width="200">
      </el-table-column>
      <el-table-column sortable prop="createTime" label="申请时间" width="200">
      </el-table-column>
      <el-table-column sortable prop="modificationTime" label="修改时间" width="150">
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope" >
          <el-button size="mini" type="danger" @click="updateService(scope.$index, scope.row)">修改状态</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination  style="text-align: center;"
    :total="pages.total"
    :current-page="pages.pageNum"
    :page-size="pages.pageSize"
    :page-sizes="pages.pageSizes"
    @current-change="changeNum"
    @size-change="sizesChange"
    layout="total,prev,pager,next,jumper,sizes">
    </el-pagination>
  </div>
</template>

<script>
import {
  MachineConfigList,
  MachineConfigSave,
  MachineConfigDelete,
  MachineConfigUpdate
} from '../../api/payMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      pages:{
      	total:0,
      	pageSize:5,
      	pageNum:1,
      	pageSizes:[5,10,15]
      },
      listTh:[], //替换数据
      listData: [] //申诉数据
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    var params={pageNum:this.pages.pageNum,pageSize:this.pages.pageSize}
    this.getdata(params)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata(parameter) {
      this.loading = true

      /* **
       * 调用接口，注释上面模拟数据 取消下面注释
       */
       MachineConfigList(parameter)
         .then(res => {
           this.loading = false
           if (res.code != 1) {
             this.$message({
               type: 'info',
               message: res.msg
             })
           } else { //
             this.listTh = res.data.list
             for (var i = 0; i < this.listTh.length; i++) {
               if(this.listTh[i].serviceState==1){
                 this.listTh[i].serviceState='已处理'
               }else{
                 this.listTh[i].serviceState='未处理'
               }
             }
             this.listData = this.listTh
             this.pages.total = res.data.total
           }
         })
         .catch(err => {
           this.loading = false
           this.$message.error('菜单加载失败，请稍后再试！')
         })
    },
    sizesChange(value){
      this.pages.pageSize=value;
      var params={pageNum:this.pages.pageNum,pageSize:value}
    	this.getdata(params)
    },
    changeNum(value){
      var params={pageNum:value,pageSize:this.pages.pageSize}
    	this.getdata(params)
    },
     updateService(index, row) {
        this.$confirm('确定修改吗?', '信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
          var params={'serviceId':row.id}
          MachineConfigUpdate(params)
            .then(res => {
              if (res.code>0) {
                this.$message({
                  type: 'success',
                  message: '状态已修改!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('状态修改失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消修改'
          })
        })
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>
